package org.hu.vhr.controller.interview;

import org.hu.vhr.model.Interview;
import org.hu.vhr.model.RespBean;
import org.hu.vhr.service.EmpBasicService;
import org.hu.vhr.service.InterviewService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/interview")
public class InterviewController {
    public final static Logger logger = LoggerFactory.getLogger(InterviewController.class);

    @Autowired
    RabbitTemplate rabbitTemplate;
    @Autowired
    InterviewService interviewService;

    @PostMapping("/")
    public RespBean insertInterview(@RequestBody Interview interview){
        logger.info(interview.toString());
        Integer result = interviewService.insertInterview(interview);
        if (result == 1) {
            rabbitTemplate.convertAndSend("hcy.mail.interview", interview);
            return RespBean.success("自动预约成功");
        }else{
            return RespBean.error("该面试官此时间段已有面试");
        }
    }

    @GetMapping("/")
    public List<Interview> getAllInterview(){
        return interviewService.getAllInterview();
    }

    @GetMapping("/newEmps")
    public List<Interview> getAllNewEmps(){
        return interviewService.getAllNewEmps();
    }

    @PutMapping("/")
    public RespBean updateInfoStatus(@RequestBody Interview interview){
        if(interviewService.updateInfoStatus(interview)==1){
            return RespBean.success("自动填充成功");
        }else{
            return RespBean.error("自动填充失败");
        }
    }
    @PutMapping("/pass")
    public RespBean Pass(@RequestBody Interview interview){
        interview.setStatus(1);
        interview.setInfostatus(1);
        logger.info(interview.toString());
        if(interviewService.updateStatus(interview)!= 0){
            return RespBean.success("更新成功");
        }else{
            return RespBean.error("更新失败");
        }
    }

    @PutMapping("/reject")
    public RespBean Reject(@RequestBody Interview interview){
        interview.setStatus(2);
        logger.info(interview.toString());
        if(interviewService.updateStatus(interview)!= 0){
            return RespBean.success("更新成功");
        }else{
            return RespBean.error("更新失败");
        }
    }
}
